<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script>
        var bookList = [{id:3,name:"三国",price:30},{id:5,name:"红楼",price:50},{id:8,name:"西游",price:35}];

        //[{book:{id:3,name:"三国",price:30},num:1}]
        var shopList = [];
        function addShop(bookId){
            var shopBean = shopList.find(n => n.book.id == bookId);
            if(shopBean != null){//商品存在
                shopBean.num ++;
            }
            else{//商品不存在
                var book = bookList.find(n => n.id == bookId);
                //速写属性，如果属性名和属性值相同时，可以只写属性
                var shop = {book:book,num:1};
                shopList.push(shop);
            }

        }

    </script>
</head>
<body>

</body>
</html>